//
//  ViewController.m
//  10-homeWork-YICheCell
//
//  Created by 王道林 on 16/7/27.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "ViewController.h"
#import "CustomHeaderView.h"
#import "ListTableViewCell.h"
#import "ModelOfList.h"
@interface ViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) NSMutableArray *marrCycle;
@property (nonatomic, strong) NSMutableArray *marrList;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self createData];
    [self createSubView];
    
}
- (void)createData
{
    _marrCycle = [NSMutableArray array];
    _marrList = [NSMutableArray array];
    NSString *path = [[NSBundle mainBundle] pathForResource:@"YiChe" ofType:@"plist"];
    NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile:path];
    NSLog(@"%@", dic);
    // 将数据解析分解
    NSDictionary *dicData = [dic objectForKey:@"data"];
    NSArray *arr = [dicData objectForKey:@"cycleImage"];

    for (NSDictionary *dic1 in arr) {
        [_marrCycle addObject:[dic1 objectForKey:@"picCover"]];
    }
    NSArray *arrList = [dicData objectForKey:@"list"];
    for (NSDictionary *dic in arrList) {
        ModelOfList *model = [[ModelOfList alloc] init];
        [model setValuesForKeysWithDictionary:dic];
        [_marrList addObject:model];
    }
    

}

-(void)createSubView
{
    _tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
    
    // 注册
    [_tableView registerClass:[ListTableViewCell class] forCellReuseIdentifier:@"Function"];
    [self createHeaderView];
}

- (void)createHeaderView
{

    CustomHeaderView *HeaderView = [[CustomHeaderView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 280) PicArray:_marrCycle];
    _tableView.tableHeaderView = HeaderView;
}




- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _marrList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ListTableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:@"Function" forIndexPath:indexPath];
    ModelOfList *model = _marrList[indexPath.row];
    cell.model = model;
    return cell;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
